#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
#include<unistd.h>


int main()
{
    umask(0);//设置默认权限掩码为0
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_TRUNC,0666);
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_APPEND,0666);
    int fd = open("log.txt",O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return 1;
    }

    //printf("fd : %d\n",fd);

    char buffer[128];
    ssize_t s = read(fd,buffer,sizeof(buffer)-1);
    if(s > 0)
    {
        buffer[s] = '\0';
        printf("%s",buffer);
    }

   // const char* msg = "hello file\n";
   // int count = 0;
   // while(count < 5)
   // {
   //     write(fd,msg,strlen(msg)); // msg:缓冲区首地址;len:本次读取，期望写入多少个字节的数据;返回值：实际写了多少字节数据
   //     count++;
   // }

    close(fd);
    return 0;
}
